package com.qeeyou.apps.android.craftsman.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.qeeyou.apps.android.craftsman.activity.home.SchedulingActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xuchengxiong on 2018/2/6.
 */

public class TabAdpater extends FragmentPagerAdapter {

    private List<Fragment> fragmentList;

    public TabAdpater(FragmentManager manager, List<Fragment> fragmentList) {
        super(manager);
        if(this.fragmentList == null) {
            this.fragmentList = new ArrayList<Fragment>();
        }
        this.fragmentList.clear();
        if(fragmentList != null) {
            this.fragmentList.addAll(fragmentList);
        }
    }

    public void setItems(List<Fragment> fragmentList) {
        if(this.fragmentList == null) {
            this.fragmentList = new ArrayList<Fragment>();
        }
        this.fragmentList.clear();
        if(fragmentList != null) {
            this.fragmentList.addAll(fragmentList);
        }
        notifyDataSetChanged();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return SchedulingActivity.tabTitle[position];
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }
}

